import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { CommonEntity } from '@/common/entities/base.entity';
import { ApiProperty } from '@nestjs/swagger';
import { Menu } from '@/module/menu/entities/menu.entity';

@Entity({
  name: 'sys_menu_buttons',
  comment: '按钮表',
})
export class Buttons extends CommonEntity {
  @ApiProperty({ type: Number, description: '按钮ID' })
  @PrimaryGeneratedColumn({
    type: 'bigint',
    name: 'id',
    comment: '按钮ID',
  })
  id: number;

  @ApiProperty({ type: String, description: '按钮名称' })
  @Column({
    type: 'varchar',
    name: 'name',
    nullable: true,
    comment: '按钮名称',
  })
  name: string;


  @ApiProperty({ type: String, description: '权限标识' })
  @Column({
    comment: '权限标识',
    nullable: true,
  })
  permission: string;


  @ApiProperty({ type: Number, description: '关联菜单ID' })
  @Column({
    comment: '关联菜单ID',
    type: 'bigint',
    nullable: true,
    name: 'menu_id',
  })
  menuId: number;

  @ManyToOne(() => Menu, (menu) => menu.buttons)
  @JoinColumn({
    name: 'menu_id',  // 指定外键列的数据库实际列名
    referencedColumnName: 'id'  // 关联的目标实体的列名
  })
  menu: Menu;
}
